//
//  ViewEvalutionTeacherController.m
//  SDSY
//
//  Created by 蓝布鲁 on 2017/4/13.
//  Copyright © 2017年 蓝布鲁. All rights reserved.
//

#import "ViewEvalutionTeacherController.h"
#import "TeacherInfoHeaderView.h"
#import "UserInfoModel.h"
#import "EvalutionTeacherModel.h"

@interface ViewEvalutionTeacherController ()
// 视图
@property (weak, nonatomic) IBOutlet TeacherInfoHeaderView *headerView;             // 导师简介
@property (strong, nonatomic) IBOutletCollection(UIImageView) NSArray *stars;       // 星星
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;                           // 分数
@property (weak, nonatomic) IBOutlet UILabel *evalutionLabel;                       // 评论内容

// 数据
@property (nonatomic,retain) EvalutionTeacherModel *evalutionModel;                 // 评价模型
@property (nonatomic, retain)TeacherInfoModel *model;          // 导师模型

@end

@implementation ViewEvalutionTeacherController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"查看评论";
    // 网络请求
    [self updateEvalution];
    [self updateTeacherInfo];
}

#pragma mark - 网络请求
-(void)updateEvalution {
    [[NetworkTool shareInstance] requireMethodType:POSTType
                                         URLString:@"SDSY/getMycomitTeacher"
                                        parameters:@{@"yy_id": @(self.yyid), @"s_id": [UserInfoModel shareInstance].stu_id}
                                           success:^(NSDictionary *respondDictionary) {
                                               // 转化模型
                                               self.evalutionModel = [[EvalutionTeacherModel alloc] initWithDictionary:respondDictionary];
                                               
                                               // 点亮评分对应的星星
                                               for (int i = 0; i < self.evalutionModel.script; i++) {
                                                   UIImageView *imageView = self.stars[i];
                                                   imageView.image = [UIImage imageNamed:@"star_orange"];
                                               }
                                               
                                               // 更新评分Label
                                               self.scoreLabel.text = [NSString stringWithFormat:@"%d分",self.evalutionModel.script];
                                               
                                               // 更新评分内容
                                               self.evalutionLabel.text = self.evalutionModel.evaluationitem;
                                               self.evalutionLabel.height = [self.evalutionModel.evaluationitem heightWithFont:[UIFont systemFontOfSize:15] width:self.evalutionLabel.width] + 20;
                                           } failure:^(NSError *error) {
                                               
                                           }];
}

-(void)updateTeacherInfo {
    [[NetworkTool shareInstance] requireMethodType:POSTType
                                         URLString:@"SDSY/getTeacherInfo"
                                        parameters:@{@"s_id": [UserInfoModel shareInstance].stu_id, @"tea_id": self.teacherID}
                                           success:^(NSDictionary *respondDictionary) {
                                               self.model = [[TeacherInfoModel alloc] initWithDictionary:respondDictionary[@"teacherInfo"]];
                                               // 设置header模型
                                               self.headerView.model = self.model;

                                           }
                                           failure:^(NSError *error) {
                                               
                                           }];



}



@end
